package cn.baker.redssion.controller;

import cn.baker.delayqueue.util.RedisDelayQueueUtil;
import cn.baker.redssion.delayqueue.entity.TestDelayQueueDTO;
import cn.baker.redssion.delayqueue.enums.RedisDelayQueueEnum;
import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * 延迟队列测试
 */
@Slf4j
@RestController
public class RedisDelayQueueController {
 
    @Autowired
    private RedisDelayQueueUtil redisDelayQueueUtil;


    /**
     * http://localhost:8848/testDelayQueue?delay=5
     */
    @RequestMapping("/testDelayQueue")
    public void addQueue(@RequestParam(value = "delay") Long delay) throws JsonProcessingException {
        TestDelayQueueDTO testDelayQueueDTO = TestDelayQueueDTO.builder().time(System.currentTimeMillis()).delay(TimeUnit.SECONDS.toMillis(delay)).build();

        redisDelayQueueUtil.addDelayQueue(testDelayQueueDTO, delay, TimeUnit.SECONDS, RedisDelayQueueEnum.TEST_DELAY_QUEUE.getCode());
    }

 
}